Apache Struts 2 Web Application Development by Dave Newton

Apache Struts 2 Web Application Development by Dave Newton

Author:Dave Newton [Dave Newton ]
Language: eng
Format: epub, pdf
Publisher: Packt Publishing


The servletConfig interceptor

The servletConfig interceptor sets various servlet-specification-related variables (for example, the session attribute map) on appropriate actions. We discussed the servletConfig interceptor when we covered the ApplicationAware, SessionAware, RequestAware, ParameterAware, ServletRequestAware, ServletResponseAware, and the ServletContextAware interfaces.

All this interceptor does is check for the implementation of each of the interfaces listed earlier (plus PrincipalAware) and set the appropriate action property if the action implements the corresponding interface.

For example, if our action implements SessionAware, it must implement the method void setSession(Map). The servletConfig interceptor checks for an implementation of SessionAware. If found, it casts the action to SessionAware and sets the session attribute map using the setSession() method, using code similar to the following (it's more or less the same idea for the other interfaces):

public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); ActionContext context = invocation.getInvocationContext(); if (action instanceof SessionAware) { ((SessionAware) action) setSession(context.getSession()); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.